package leistungsbewertung;

import java.util.Vector;

import javax.swing.SwingUtilities;

//Ereignisliste
public class EventChain {

	Vector<Event> eventArrival;
	Vector<Event> eventCompletion;

	public EventChain() {
		this.eventArrival = new Vector<Event>(0);
		this.eventCompletion = new Vector<Event>(0);
//		runEvents();
	}

	public void addEvent(Event e) {
		if (e.isArrival()) {
			this.eventArrival.add(e);
		} else {
			this.eventCompletion.add(e);
		}

	}

	public void runEvents() {

		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				System.out.println("Test");
//				CompletionThread cT = new CompletionThread();
				ArrivalThread aT = new ArrivalThread();
				aT.start();
//				cT.start();

			}
		});

	}

	class ArrivalThread extends Thread {
		Event e;

		public ArrivalThread() {
			System.out.println("started Arrival Thread");
			while (true) {
				if (eventArrival.size() > 0) {
					e = eventArrival.get(0);
					e.customerArrival(new Customer());
				}
			}

		}
	}

	class CompletionThread extends Thread {
		Event e;

		public CompletionThread() {
			while (true) {
				if (eventCompletion.size() > 0) {
					e = eventCompletion.get(0);
					e.serviceCompletion(new Customer());
				}
			}
		}

	}

	public Vector<Event> getEventArrival() {
		return eventArrival;
	}

	public Vector<Event> getEventCompletion() {
		return eventCompletion;
	}

}